<template>
  <div class="view-container">
    <div class="main-content">
      <div class="list-container">
        <div class="my-tabs-container">
          <div class="my-tabs">
            <el-tabs
              v-model="activeName"
              @tab-click="handleClick"
            >
              <el-tab-pane
                label="收款管理"
                name="payeeList"
              />
              <el-tab-pane
                label="保证金"
                name="cashDepositList"
              />
              <el-tab-pane
                label="货款"
                name="goodsPaymentList"
              />
            </el-tabs>
          </div>
        </div>
        <component
          :is="activeName"
          ref="comp"
          navigation="finance"
        />
      </div>
    </div>
    <create-cash-deposit
      ref="cashRef"
      @handleSuccess="createSuccess"
    />
  </div>
</template>

<script>
import { defineAsyncComponent, reactive, toRefs } from 'vue'
import { useRoute, useRouter } from 'vue-router'

export default {
  components: {
    payeeList: defineAsyncComponent(() =>
      import('@CRM/views/returnedRecords/returnedMoney/list/payeeList.vue')
    ),
    cashDepositList: defineAsyncComponent(() =>
      import('./cashDepositList.vue')
    ),
    goodsPaymentList: defineAsyncComponent(() =>
      import('./goodsPaymentList.vue')
    ),
    createCashDeposit: defineAsyncComponent(() =>
      import('../modules/createCashDeposit.vue')
    ),
  },
  setup(props, context) {
    const route = useRoute()
    const router = useRouter()
    var datas = reactive({
      activeName: route.query.tabs || 'payeeList',
      cashRef: null,
      comp: null,
    })
    const handleClick = (tab, event) => {
      console.log(tab, event)
      router.push({
        name: 'returnedMoney2',
        query: {
          tabs: tab.props.name,
        },
      })
    }
    const createCashDeposit = () => {
      datas.cashRef.open()
    }
    const createSuccess = () => {
      datas.comp.refreshList()
    }
    return {
      ...toRefs(datas),
      handleClick,
      createCashDeposit,
      createSuccess,
    }
  },
}
</script>

